package com.bdqn.carrental.controller;

import com.bdqn.carrental.pojo.catinfo;
import com.bdqn.carrental.service.CatinfoServiceimpl;

import com.bdqn.carrental.service.UserServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller //证明是controller层并且返回json
@RequestMapping(value = "/catinfo")
public class CatinfoController {

    @Autowired
    CatinfoServiceimpl catinfoServiceimpl;

    private String meg=null;//页面弹框标识符

    /**
     * 查询汽车信息并分页
     * @return
     */
    @RequestMapping(value = "/catlist",method = RequestMethod.GET)
    public String  catinfoList(Model model,
                                  @RequestParam(value = "pinpai",required = false)String pinpai,
                                  @RequestParam(value = "pageNum",required = false)String _pageNum  ) {
        Integer pageNum=1;
        if(_pageNum!=null){
            pageNum=Integer.parseInt(_pageNum);
        }
        String pinpais="";
        if (pinpai!=null){
            pinpais=pinpai;
        }
        //引入分页查询，使用PageHelper分页功能
        //在查询之前传入当前页，然后多少记录
        PageHelper.startPage(pageNum,2);
        //startPage后紧跟的这个查询就是分页查询
        List<catinfo> catinfolist =catinfoServiceimpl.catInfolist(pinpai);
        //使用PageInfo包装查询结果，只需要将pageInfo交给页面就可以7
        PageInfo<catinfo> page=new PageInfo<catinfo>(catinfolist);
        model.addAttribute("pageInfocat",page);
        model.addAttribute("meg",meg);
        model.addAttribute("pinpais",pinpais);
        meg=null;
        return "yg-jbxxcat";
    }

}
